﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch01
{
    public partial class Form2 : Form
    {
        Point p1, p2;
        bool flag = false;
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        //窗体单击事件
        private void Form2_Click(object sender, EventArgs e)
        {
            //移动窗体的位置
            //this.Location = new Point(500,200);
        }

        private void Form2_MouseDown(object sender, MouseEventArgs e)
        {
            p1 = MousePosition;
            p2 = Location;
            flag = true;
        }

        private void Form2_MouseUp(object sender, MouseEventArgs e)
        {
            flag = false;
        }
        //开始图片框单击事件
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            //让timer计时器启动，开始执行
            timer1.Start();
        }
        //时间间隔事件
        private void timer1_Tick(object sender, EventArgs e)
        {
            //生成6个随机数并放到对应的标签上

            //创建一个随机数对象
            Random rand = new Random();
            //生成随机数
            label1.Text = rand.Next(10).ToString();
            label2.Text = rand.Next(10).ToString();
            label3.Text = rand.Next(10).ToString();
            label4.Text = rand.Next(10).ToString();
            label5.Text = rand.Next(10).ToString();
            label6.Text = rand.Next(10).ToString();
        }
        //停止图片框单击事件
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            //让timer计时器停止执行
            timer1.Stop();
        }

        private void Form2_MouseMove(object sender, MouseEventArgs e)
        {
            if (flag)
            {
                int x = MousePosition.X - p1.X;
                int y = MousePosition.Y - p1.Y;
                Location = new Point(p2.X + x, p2.Y + y);
            }
        }
    }
}
